import cameras

class LinearTransitionBehavior(cameras.CameraBehavior):
    __guid__ = 'cameras.LinearTransitionBehavior'

    def __init__(self, transitionSeconds = 1.0):
        cameras.CameraBehavior.__init__(self)
        self.transitionSeconds = transitionSeconds
        self.doneSeconds = 0
        self.changeX = None
        self.changeY = None
        self.changeZ = None
        self.changeYaw = None
        self.changePitch = None



    def ProcessCameraUpdate(self, camera, now, frameTime):
        self.changeX = (camera.toPoint[0] - camera.fromPoint[0])
        self.changeY = (camera.toPoint[1] - camera.fromPoint[1])
        self.changeZ = (camera.toPoint[2] - camera.fromPoint[2])
        self.changeYaw = (camera.toRotation.yaw - camera.fromRotation.yaw)
        self.changePitch = (camera.toRotation.pitch - camera.fromRotation.pitch)
        animPosition = (float(self.doneSeconds) / float(self.transitionSeconds))
        newX = (camera.fromPoint[0] + (self.changeX * animPosition))
        newY = (camera.fromPoint[1] + (self.changeY * animPosition))
        newZ = (camera.fromPoint[2] + (self.changeZ * animPosition))
        newYaw = (camera.fromRotation.yaw + (self.changeYaw * animPosition))
        newPitch = (camera.fromRotation.pitch + (self.changePitch * animPosition))
        self.doneSeconds += frameTime
        if (self.doneSeconds >= self.transitionSeconds):
            (newX, newY, newZ,) = (camera.toPoint[0], camera.toPoint[1], camera.toPoint[2])
            (newYaw, newPitch,) = (camera.toRotation.yaw, camera.toRotation.pitch)
            camera.DoneTransitioning()
        camera.SetPosition((newX,
         newY,
         newZ))
        camera.SetYaw(newYaw)
        camera.SetPitch(newPitch)




